
module.exports = {
	uid:'',
	createUserName:'',
	username : '',
	password : '',
	token : '',
	tabbar1:[],
	tabbar2:[],
	tabbar3:[],
	getUserByLogin : async function(usernames,passwords,myRequest){
		if(usernames == ''||passwords == ''){
			uni.showToast({
				title:"用户名或密码不能为空..."
			});
		}
		uni.showLoading({
			title:"登陆中...",
			mask:true
		})
		this.username = usernames;
		this.password = passwords;
		myRequest({
			url:'/user/getUserByLogin',
			data:{
				username:this.username,
				password:this.password
			},
		}).then(rep => {
			if(rep.code == "success"){
				this.token = rep.data.token;
				uni.showLoading({
					title:"登陆成功，验证权限中...",
					mask:true
				});
				myRequest({
					url:'/user/getMenuByToken',
					data:{token:this.token},
				}).then(res => {
					if(res.code == 0){
						const userList = res.rows;
						for(let i = 0; i<userList.length;i++){
							if(userList[i].mpid >= 6 && userList[i].mpid <= 9 && userList[i].mpid != 8){
								this.tabbar1.push({
									name:userList[i].pmName,
									open:false
								});
							}else if (userList[i].mpid >= 10 && userList[i].mpid <= 12){
								let src = userList[i].src
								let fileName = src.substring(src.indexOf('/')+1,src.indexOf('.'))
								this.tabbar2.push({
									name:userList[i].pmName,
									open:false,
									src: fileName
								});
							}else if(userList[i].mpid == 17||userList[i].mpid == 18){
								this.tabbar3.push({
									name:userList[i].pmName,
									open:false,
								});
							}
						}
					}
					uni.hideLoading();
					uni.showToast({
						title:"验证成功！",
						icon:"success",
						duration:2000
					});
					setTimeout(function() {
						uni.switchTab({
							url:'../tabbar/tabbar-1/tabbar-1'
						})
					}, 2000);
				});
				myRequest({
					url:'/user/getUserInfoByToken',
					data:{token:this.token},
				}).then(res1 => {
					if(res1.code == 0){
						this.createUserName = res1.rows[0].userName;
						this.uid = res1.rows[0].uid;
					}
				});
				
			}else{
				uni.showToast({
					title:"登陆失败！msg："+rep.message,
					icon:"none"
				});
			}
		})
	}
}
